/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servant;

import java.io.File;
import servant.XMLBuilder.XMLBuilderError;
import org.apache.tools.ant.*;
import java.util.Hashtable;
import java.util.Vector;

/**
 *
 * @author Mateusz
 */
public class TaskRunner {

    private String mainPath;
    private String testPath;
    private String resultPath;
    private XMLBuilder builder;

    public TaskRunner(String mainPath, String testPath, String resultPath) throws XMLBuilderError {
        this.mainPath = mainPath;
        this.testPath = testPath;
        this.resultPath = resultPath;
        this.builder = new XMLBuilder();
    }

    public void compile() {
        //try {
        //org.apache.tools.ant.Main main = new org.apache.tools.ant.Main();
        //Properties p = new Properties();
        //main.startAnt(new String[]{"-buildfile", mainPath+"/build.xml"}, p, new ClassLoader() {});
        Project project = new Project();
        project.init();

        File buildFile = new File(mainPath, "build.xml");
        ProjectHelper.configureProject(project, buildFile);
        project.addBuildListener(new JUnitXMLBuildListener());

        System.out.println("A");
        Hashtable t = project.getTargets();
        System.out.println("B");
        //t.remove("-do-compile-test-single");
        System.out.println("C");
        project.executeTargets(new Vector(t.keySet()));
        System.out.println("D");

        /*Runtime rt = Runtime.getRuntime();
        Process pr = rt.exec("ant -buildfile " + mainPath + "/build.xml");
        BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

        String line = null;

        while ((line = input.readLine()) != null) {
        System.out.println(line);
        }

        int exitVal = pr.waitFor();
        System.out.println("Exited with error code " + exitVal);
        } catch (InterruptedException ex) {
        Logger.getLogger(TaskRunner.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
        Logger.getLogger(TaskRunner.class.getName()).log(Level.SEVERE, null, ex);
        }*/

    }

    public void run() {
    }
}
